package com.acme.task1;

/**
 * @author Java Student
 *
 */
public class Calculator {

	public static final char OPER_PLUS     = '+';
	public static final char OPER_MINUS    = '-';
	public static final char OPER_MULTIPLY = '*';
	public static final char OPER_DIVIDE   = '/';
	
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		
		calc(args);
				
	}
	
	public static void calc(String[] args){
		
		double operand1, operand2, result=0;
		
		if(!check(args)){
			throw new IllegalArgumentException();
		}
		
		try{
			operand1 = Double.parseDouble(args[0]);;
			operand2 = Double.parseDouble(args[2]);;
		} catch(NumberFormatException nfe) {
			throw new IllegalArgumentException();
		}
		
		// '*' 
		char c;
		if(args[1].length() > 1 ){
			c = args[1].charAt(1);
		} else {
			c = args[1].charAt(0);
		}
		
		switch (c) {
		case Calculator.OPER_PLUS:
			result = operand1 + operand2;
			break;
		case Calculator.OPER_MINUS:
			result = operand1 - operand2;
			break;
		case Calculator.OPER_MULTIPLY:
			result = operand1 * operand2;
			break;
		case Calculator.OPER_DIVIDE:
			if(operand2 == 0.0)
				throw new IllegalArgumentException();
			result = operand1 / operand2;
			break;
		default:
			throw new IllegalArgumentException();
		}
		
		
		System.out.println(result);
		
	}
	
	public static boolean check(final String[] args){
		
		if(args.length != 3)
			return false;
			
		return true;
	}

}
